package com.ruoyi.system.service.zhaungxiuservice.shopService.impl;

import com.ruoyi.system.domain.zhuangxiumain.shopMain.PreferentialCard;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.PreferentialCardMapper;
import com.ruoyi.system.service.zhaungxiuservice.shopService.PreferentialCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PreferentialCardServiceImpl implements PreferentialCardService {

    @Autowired(required = false)
    private PreferentialCardMapper preferentialCardMapper;

//    @Scheduled(fixedRate = 2000)
//    public void fixedRate() {
//        PreferentialCard preferentialCard = new PreferentialCard();
//        Long numTime = preferentialCard.getNumTime();
//        System.err.println("*******************numTimenumTimenumTime*******************"+ numTime);
//        preferentialCard.setNumTime(numTime);
//        preferentialCardMapper.updateState(preferentialCard);
//        System.err.println("*************************************************fixedRate>>>"+new Date());
//    }

    @Override
    public PreferentialCard selectPreferentialCardById(Integer preferentialId)
    {
//        this.fixedRate();
        return preferentialCardMapper.selectPreferentialCardById(preferentialId);
    }

    /**
     * 查询优惠卷列表
     *
     * @param supplierId 优惠卷
     * @return 优惠卷
     */
    @Override
    public List<PreferentialCard> selectPreferentialCardList(Integer supplierId)
    {

        return preferentialCardMapper.selectPreferentialCardList(supplierId);
    }

    @Override
    public Date selectTime(PreferentialCard preferentialCard) {
        return preferentialCardMapper.selectTime(preferentialCard);
    }

    /**
     * 新增优惠卷
     *
     * @param preferentialCard 优惠卷
     * @return 结果
     */
    @Override
    public int insertPreferentialCard(PreferentialCard preferentialCard)
    {

        Date preferentialTime = preferentialCard.getPreferentialTime();
        Date modifiedTime = preferentialCard.getModifiedTime();

        if (modifiedTime.after(preferentialTime)){
            return 0;
        }else{
            Integer numsupplierId = preferentialCard.getNumsupplierId();
            preferentialCard.setSupplierId(numsupplierId);

            return preferentialCardMapper.insertPreferentialCard(preferentialCard);
        }
    }

    /**
     * 修改优惠卷
     *
     * @param preferentialCard 优惠卷
     * @return 结果
     */
    @Override
    public int updatePreferentialCard(PreferentialCard preferentialCard)
    {
        return preferentialCardMapper.updatePreferentialCard(preferentialCard);
    }

    @Override
    public int updateState(PreferentialCard preferentialCard) {
        return preferentialCardMapper.updateState(preferentialCard);
    }

    /**
     * 批量删除优惠卷
     *
     * @param preferentialIds 需要删除的优惠卷ID
     * @return 结果
     */
    @Override
    public int deletePreferentialCardByIds(Integer[] preferentialIds)
    {
        return preferentialCardMapper.deletePreferentialCardByIds(preferentialIds);
    }

    /**
     * 删除优惠卷信息
     *
     * @param preferentialId 优惠卷ID
     * @return 结果
     */
    @Override
    public int deletePreferentialCardById(Integer preferentialId)
    {
        return preferentialCardMapper.deletePreferentialCardById(preferentialId);
    }
}
